IF OBJECT_ID('ssf.dpnd_print_object_header') IS NOT NULL
	DROP PROCEDURE ssf.dpnd_print_object_header
GO

CREATE PROCEDURE ssf.dpnd_print_object_header
	@object_name NVARCHAR(256)
AS
/*
<object_header>

<object_summary>
	<purpose><![CDATA[
Try to parse and derive an object header, then merge the xml, transform to text, and print result.
	]]></purpose>
</object_summary>

</object_header>
*/

SET NOCOUNT ON

-- ============
/*<code_comment><![CDATA[declare local variables]]></code_comment>*/
DECLARE	@parsed XML
			, @derived XML
			, @text NVARCHAR(MAX) = NULL
-- ============

-- ============
/*<code_comment><![CDATA[Because this is openSSF, default schema to "ssf" if it makes sense, making "ssf" like a secondary default schema.
Useful when calling this procedure from a keyboard shortcut and the default schema is not "ssf".]]></code_comment>*/
IF OBJECT_ID(@object_name) IS NULL
AND PARSENAME(@object_name, 2) IS NULL
AND OBJECT_ID(N'ssf.' + @object_name) IS NOT NULL
	SET @object_name = N'ssf.' + @object_name
-- ============

-- ============
/*<code_comment><![CDATA[parse object header]]></code_comment>*/
EXECUTE ssf.dpnd_parse_object_header
	@object_name = @object_name
	, @object_header = @parsed OUTPUT
-- ============

-- ============
/*<code_comment><![CDATA[derive object header]]></code_comment>*/
EXECUTE ssf.dpnd_derive_object_header
	@object_name = @object_name
	, @object_header = @derived OUTPUT
-- ============

-- ============
/*<code_comment><![CDATA[exit if null object header]]></code_comment>*/
IF @derived IS NULL
	RETURN @@ERROR
-- ============

-- ============
/*<code_comment><![CDATA[merge object headers and get text]]></code_comment>*/
SET @text = ssf.dpnd_transform_object_header_as_text(
	ssf.dpnd_merge_parsed_with_derived_object_header(@parsed, @derived)
)
-- ============

-- ============
/*<code_comment><![CDATA[print text of object header]]></code_comment>*/
PRINT(@text)
-- ============

RETURN @@ERROR
GO
